package com.itheima.Work01;

import com.itheima.reflect.Student;

import java.lang.reflect.Field;

public class work04 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Student01 stu =new Student01();

        setProperty(stu,"name","迪丽热巴");
        System.out.println(stu);

    }
    public static void  setProperty(Object obj, String propertyName,String value) throws NoSuchFieldException, IllegalAccessException {
        Class<?> clazz = obj.getClass();
        Field field = clazz.getDeclaredField(propertyName);
        field.setAccessible(true);
        field.set(obj,value);

    }
}
